package com.study.sfd.person.controller;

import com.study.common.utils.Result;
import com.study.sfd.person.vo.RegisterVo;
import com.study.sfd.person.entity.AccountEntity;
import com.study.sfd.person.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;



/**
 * account(账户)
 *
 * @author 王个球
 * @email wangdajunzy@163.com
 * @date 2021-11-12 13:45:41
 */
@RestController
@RequestMapping("person/account")
public class AccountController {
    @Autowired
    private AccountService accountService;

    @PostMapping("/register")
    public Result<?> register(@RequestBody RegisterVo registerVo)
    {
        AccountEntity accountByPhone = accountService.lambdaQuery()
                .eq(AccountEntity::getPhone, registerVo.getPhone())
                .one();
        if (accountByPhone != null) {
            return Result.error("手机号已经被注册");
        }
        accountService.register(registerVo);
        return Result.success();
    }

    @PostMapping("/login")
    public Result<?> login(String phone, String password)
    {
        return accountService.login(phone, password);
    }
}
